﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SevenInvaders.common;
using SevenInvaders.LEVEL_PEDRO;


namespace SevenInvaders
{
    class PedroRenatoPlayer : Player
    {
        animation animation1;

        public int vidaPlayer1 = 3;

        public int vidaPlayer2 = 3;

        public int pontos = 0, pontosPlayer1 = 0, pontosPlayer2 = 0;

        float milisegundo;

        Texture2D texturaTiro;

        int player;

        public PedroRenatoPlayer(Texture2D texture, Vector2 position, int player, GameWindow gameWindow, ContentManager Content, Texture2D texturaTiro)
            : base(texture, position, player, gameWindow, Content)
        {
            animation1 = new animation();
            animation1.frame.X = 0;
            animation1.frame.Y = 0;
            animation1.frame.Width = 57;
            animation1.frame.Height = 63;

            animation1.frames = 2;
            animation1.fps = 10;

            current_animation = animation1;

            this.player = player;

            this.texturaTiro = texturaTiro;
        }

        public void Update(GameTime gameTime, KeyboardState ks, KeyboardState ks_old)
        {


            // PLAYER 1 ------------------------------------------------------

            if (vidaPlayer1 > 0)
            {

                if (player == 1)
                {
                    #region Movimentação
                    if (ks.IsKeyDown(Keys.D))
                    {
                        this.PositionX += 10;
                    }

                    if (ks.IsKeyDown(Keys.A))
                    {
                        this.PositionX -= 10;
                    }

                    if (ks.IsKeyDown(Keys.W))
                    {
                        this.PositionY -= 10;
                    }

                    if (ks.IsKeyDown(Keys.S))
                    {
                        this.PositionY += 10;
                    }
                    #endregion

                    if (ks.IsKeyDown(Keys.J) && !ks_old.IsKeyDown(Keys.J))
                    {
                        Shoot.list.Add(new Shoot(texturaTiro, new Vector2(this.Position.X + this.Texture.Width / 4 - texturaTiro.Width / 2, this.PositionY), Shoot.Direction.UP, new Vector2(10, 10)));

                    }

                }
            }

            if (vidaPlayer1 <= 0)
            {
                vidaPlayer1 = 0;
            }


                // PLAYER 2 -----------------------------------------------------------------

            if (vidaPlayer2 > 0)
            {
                if (player == 2)
                {
                    #region Movimentação
                    if (ks.IsKeyDown(Keys.Right))
                    {
                        this.PositionX += 10;
                    }

                    if (ks.IsKeyDown(Keys.Left))
                    {
                        this.PositionX -= 10;
                    }

                    if (ks.IsKeyDown(Keys.Up))
                    {
                        this.PositionY -= 10;
                    }

                    if (ks.IsKeyDown(Keys.Down))
                    {
                        this.PositionY += 10;
                    }
                    #endregion

                    if (ks.IsKeyDown(Keys.NumPad1) && !ks_old.IsKeyDown(Keys.NumPad1))
                    {
                        Shoot.list.Add(new Shoot(texturaTiro, new Vector2(this.Position.X + this.Texture.Width / 4 - texturaTiro.Width / 2, this.PositionY), Shoot.Direction.UP, new Vector2(10, 10)));

                    }

                }
            }

            if (vidaPlayer2 <= 0)
            {
                vidaPlayer2 = 0;
            }

                // GERAL------------------------------------------------------------ //

                #region Colisao borda da tela
                if (this.PositionX + this.Texture.Bounds.Width / 2 > Window.ClientBounds.Width)
                {
                    this.PositionX = Window.ClientBounds.Width - this.Texture.Bounds.Width / 2;
                }

                if (this.PositionX <= 0)
                {
                    this.PositionX = 0;
                }

                if (this.PositionY + this.Texture.Bounds.Height > Window.ClientBounds.Height)
                {
                    this.PositionY = Window.ClientBounds.Height - this.Texture.Bounds.Height;
                }

                if (this.PositionY <= 0)
                {
                    this.PositionY = 0;
                }
                #endregion

                milisegundo += gameTime.ElapsedGameTime.Milliseconds;

                if (milisegundo >= 1000)
                {
                    milisegundo = 0;
                }

                if (vidaPlayer1 <= 0 && vidaPlayer2 <= 0)
                {
                    if (ks.IsKeyDown(Keys.R))
                    {
                        vidaPlayer1 = 3;
                        vidaPlayer2 = 3;
                        pontos = 0;
                    }
                }

                // -------------------------------------------------------------GERAL //

        }
    }
}
